/*     */ package com.zimbra.cs.index.query.parser;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ParseException
/*     */   extends Exception
/*     */ {
/*     */   private static final long serialVersionUID = 1L;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public Token currentToken;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public int[][] expectedTokenSequences;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public String[] tokenImage;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public ParseException(Token currentTokenVal, int[][] expectedTokenSequencesVal, String[] tokenImageVal)
/*     */   {
/*  50 */     super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal));
/*  51 */     this.currentToken = currentTokenVal;
/*  52 */     this.expectedTokenSequences = expectedTokenSequencesVal;
/*  53 */     this.tokenImage = tokenImageVal;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public ParseException() {}
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public ParseException(String message)
/*     */   {
/*  72 */     super(message);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private static String initialise(Token currentToken, int[][] expectedTokenSequences, String[] tokenImage)
/*     */   {
/* 107 */     String eol = System.getProperty("line.separator", "\n");
/* 108 */     StringBuffer expected = new StringBuffer();
/* 109 */     int maxSize = 0;
/* 110 */     for (int i = 0; i < expectedTokenSequences.length; i++) {
/* 111 */       if (maxSize < expectedTokenSequences[i].length) {
/* 112 */         maxSize = expectedTokenSequences[i].length;
/*     */       }
/* 114 */       for (int j = 0; j < expectedTokenSequences[i].length; j++) {
/* 115 */         expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');
/*     */       }
/* 117 */       if (expectedTokenSequences[i][(expectedTokenSequences[i].length - 1)] != 0) {
/* 118 */         expected.append("...");
/*     */       }
/* 120 */       expected.append(eol).append("    ");
/*     */     }
/* 122 */     String retval = "Encountered \"";
/* 123 */     Token tok = currentToken.next;
/* 124 */     for (int i = 0; i < maxSize; i++) {
/* 125 */       if (i != 0) retval = retval + " ";
/* 126 */       if (tok.kind == 0) {
/* 127 */         retval = retval + tokenImage[0];
/* 128 */         break;
/*     */       }
/* 130 */       retval = retval + " " + tokenImage[tok.kind];
/* 131 */       retval = retval + " \"";
/* 132 */       retval = retval + add_escapes(tok.image);
/* 133 */       retval = retval + " \"";
/* 134 */       tok = tok.next;
/*     */     }
/* 136 */     retval = retval + "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
/* 137 */     retval = retval + "." + eol;
/* 138 */     if (expectedTokenSequences.length == 1) {
/* 139 */       retval = retval + "Was expecting:" + eol + "    ";
/*     */     } else {
/* 141 */       retval = retval + "Was expecting one of:" + eol + "    ";
/*     */     }
/* 143 */     retval = retval + expected.toString();
/* 144 */     return retval;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/* 150 */   protected String eol = System.getProperty("line.separator", "\n");
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   static String add_escapes(String str)
/*     */   {
/* 158 */     StringBuffer retval = new StringBuffer();
/*     */     
/* 160 */     for (int i = 0; i < str.length(); i++) {
/* 161 */       switch (str.charAt(i))
/*     */       {
/*     */       case '\000': 
/*     */         break;
/*     */       case '\b': 
/* 166 */         retval.append("\\b");
/* 167 */         break;
/*     */       case '\t': 
/* 169 */         retval.append("\\t");
/* 170 */         break;
/*     */       case '\n': 
/* 172 */         retval.append("\\n");
/* 173 */         break;
/*     */       case '\f': 
/* 175 */         retval.append("\\f");
/* 176 */         break;
/*     */       case '\r': 
/* 178 */         retval.append("\\r");
/* 179 */         break;
/*     */       case '"': 
/* 181 */         retval.append("\\\"");
/* 182 */         break;
/*     */       case '\'': 
/* 184 */         retval.append("\\'");
/* 185 */         break;
/*     */       case '\\': 
/* 187 */         retval.append("\\\\");
/* 188 */         break;
/*     */       default:  char ch;
/* 190 */         if (((ch = str.charAt(i)) < ' ') || (ch > '~')) {
/* 191 */           String s = "0000" + Integer.toString(ch, 16);
/* 192 */           retval.append("\\u" + s.substring(s.length() - 4, s.length()));
/*     */         } else {
/* 194 */           retval.append(ch);
/*     */         }
/*     */         break;
/*     */       }
/*     */     }
/* 199 */     return retval.toString();
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/index/query/parser/ParseException.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */